﻿CKEDITOR.dialog.add('save',function(editor){ 
    return {
        title: "保存表单信息",
        minWidth: 320,
        minHeight: 150,
		onShow:function(){
			this.setupContent();
		},
		onOk:function(evt){
	        var data=this.getParentEditor().getData();
			if(!data || data.length<1){
				alert("当前设计器没有内容，不能执行保存动作！");
				return;
			}
			var element={};
			this.commitContent(element);
			var url = location.href;
			if(!element.name || element.name.length<1){
				alert("请输入要保存的表单名称。");
				evt.data.hide=false;
				return;									
			}
			var id="";
			if(window.formData){
				id=window.formData.getId();
			}
			var params = url.substring(url.indexOf("?"),url.length);
			$.ajax({
				async:false,
				url:contextPath+"/dorado/uflo/form/save"+params,
				data:{
					content:data,
					id:id,
					name:element.name
				},
				type:"POST",
				success:function(){
					alert("保存成功！");
				},
				error:function(req,error,exception){
					alert("保存失败！");
				}
			});
		},
        contents: [{
            id: 'info',
            label:"保存表单",
            elements: [
				{
                    id: 'name',
                    type: 'text',
					style:"width:320px",
                    label: "表单名称",
                    'default': '',
					setup:function(){
						if(window.formData){
							this.setValue(window.formData.getName());
						}
					},
                    commit:function(element){
						element.name=this.getValue();
					}  
				}
			]
        }]
    };
});
